<?php

namespace app\api\dao\admin\setting;

use app\api\common\dao\BaseDao;
use app\api\model\admin\setting\Dept;

/**
 * 系统日志
 * Class UserDao
 *
 * @package app\dao\admin
 */
class DeptDao extends BaseDao
{
    /**
     * 设置模型
     *
     * @return \app\api\common\model\BaseModel
     */
    protected function setModel(): string
    {
        return Dept::class;

    }

    /**
     * @param array|string|int $id
     * @param string|null      $key
     *
     * @return bool
     * @throws \Exception
     */

    public function delete(array|string|int $id, string|null $key = 'id'): bool
    {
        foreach ($id as $value) {
            $rows = $this->getModel()->getChildren($value);
            if (!empty($rows)) {
                throw new \Exception('包含子部门删除失败');
            }
        }
        return $this->destroy($id);
    }
}
